/*
 *  UI_VolMute.cpp
 *
 *	Date: 2011-4-29
 *  Author: linshenqi
 */

#include "stdafx.h"
#include "./UI_Frame.h"

extern CDC *g_pDC;
extern CDC g_MemDC;

#define X	32
#define Y	32

UI_BMPButton::UI_BMPButton(const CRect *pRect, const GRAPHICPROP *pProp)
	: GraphicBase(pRect, pProp)
	, m_pParent(NULL)
	, m_bFlag(false)
	, m_bStmt(false)
{}

bool UI_BMPButton::OnPaint(CPaintDC *pDC, CDC *pMemDC)
{
	//CPaintDC dc(this->m_pWnd);
	//this->SetDC(&dc);
	this->DrawBmp(this->m_pRect, &this->m_pBmp, pMemDC, pDC, 0, 0);
	CRect rc(this->m_pRect->CenterPoint().x - 4, this->m_pRect->CenterPoint().y - 12, this->m_pRect->CenterPoint().x + 4, this->m_pRect->CenterPoint().y - 6);
	this->DrawText(NULL, &rc, m_Text, RGB(0, 0, 0), pDC, pDC);

	GraphicBase::OnPaint();
	return true;
}

bool UI_BMPButton::OnLButtonDown(UINT nFlags, CPoint point)
{
	if(!this->m_pRect->PtInRect(point))
		return false;

	//this->SetDC(this->m_pWnd->GetDC());
	m_bFlag = true;

	this->SetBmp(m_pBmpEx, this->m_pRect);
	this->DrawBmp(this->m_pRect, &this->m_pBmp, &::g_MemDC, ::g_pDC, X, Y);
	CRect rc(this->m_pRect->CenterPoint().x - 4, this->m_pRect->CenterPoint().y - 12, this->m_pRect->CenterPoint().x + 4, this->m_pRect->CenterPoint().y - 6);
	this->DrawText(NULL, &rc, m_Text, RGB(0, 0, 0), ::g_pDC, ::g_pDC);

	GraphicBase::OnLButtonDown(nFlags, point);
	//this->m_pWnd->ReleaseDC(this->m_pDC);
	return true;
}

bool UI_BMPButton::OnLButtonUp(UINT nFlags, CPoint point)
{
	if(!m_bFlag)
		return false;

	//this->SetDC(this->m_pWnd->GetDC());
	m_bFlag = false;
	
	
	this->SetBmp(m_pBmpR, this->m_pRect);
	this->DrawBmp(this->m_pRect, &this->m_pBmp, &::g_MemDC, ::g_pDC, X, Y);
	CRect rc(this->m_pRect->CenterPoint().x - 4, this->m_pRect->CenterPoint().y - 12, this->m_pRect->CenterPoint().x + 4, this->m_pRect->CenterPoint().y - 6);
	this->DrawText(NULL, &rc, m_Text, RGB(0, 0, 0), ::g_pDC, ::g_pDC);
	if(this->m_pRect->PtInRect(point) && this->m_pParent)
	{
		this->m_pParent->Func(this->m_nID);
	}
	//this->m_pWnd->InvalidateRect(this->m_pRect);
	
	//m_bStmt = !m_bStmt;

	GraphicBase::OnLButtonUp(nFlags, point);
	//this->m_pWnd->ReleaseDC(this->m_pDC);
	return true;
}

bool UI_BMPButton::OnMouseMove(UINT nFlags, CPoint point)
{
	GraphicBase::OnMouseMove(nFlags, point);
	return true;
}


void UI_BMPButton::SetParam(char *pBmp, char *pBmpEx, CString& str)
{
	m_pBmpR = pBmp;
	m_pBmpEx = pBmpEx;
	m_Text = str;
	this->SetBmp(m_pBmpR, this->m_pRect);
}